package com.itbour.service.user.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.user.MemberInfoDao;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.user.MemberInfoDto;
import com.itbour.service.user.MemberInfoService;


//会员管理
public class MemberInfoServiceImpl implements MemberInfoService {

	private MemberInfoDao memberInfoDao;

	// 分页获取 会员用户信息
	public Page getMemberInfo(Map<String, Object> parm, Integer pageNum,
			Integer pageSize) {
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize = memberInfoDao.getMemberInfoCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<MemberInfoDto> data = memberInfoDao.getMemberInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}
	
	// 分页获取 一键秀会员用户信息
	public Page getYjxMemberInfo(Map<String, Object> parm, Integer pageNum,
			Integer pageSize) {
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize = memberInfoDao.getYjxMemberInfoCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<MemberInfoDto> data = memberInfoDao.getYjxMemberInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}
	
	// 分页获取 角色用户信息
	public Page getUserRoleInfo(Map<String, Object> parm, Integer pageNum,
			Integer pageSize) {
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize = memberInfoDao.getUserInfCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}
		// 分页检索
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<UserInfoDto> data = memberInfoDao.pageGetUserInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}
	
	//添加会员
	public void addMemberInfo(MemberInfoDto mem) {
		Map<String, Object> parm=new HashMap<String, Object>();
		parm.put("user_id",mem.getUser_id());
		parm.put("vip",mem.getVip());
		parm.put("desc",mem.getDesc());
		parm.put("expiry_time",mem.getExpiry_time());
		parm.put("update_by",mem.getUpdate_by());
		memberInfoDao.insertMemberInfo(parm);
	}
	//修改会员
	public void updMemberInfo(MemberInfoDto mem) {
		Map<String, Object> parm=new HashMap<String, Object>();
		if(mem.getMember_id()==null ||mem.getMember_id().equals(" ")){
			return;
		}
		parm.put("member_id",mem.getMember_id());
		List<MemberInfoDto> tep=memberInfoDao.getOneMemberInfo(parm);
		for (MemberInfoDto memberInfoDto : tep) {
			parm.put("last_expiry_time", memberInfoDto.getExpiry_time());
		}
		parm.put("user_id",mem.getUser_id());
		parm.put("vip",mem.getVip());
		parm.put("desc",mem.getDesc());
		parm.put("expiry_time",mem.getExpiry_time());
		memberInfoDao.updMemberInfo(parm);
	}
	//删除会员
	public void delMemberInfo(Map<String, Object> parm) {
		memberInfoDao.delMemberInfo(parm);
	}
	
	/**		 一键秀 会员添加
	 */
	public void addYjxMemberInfo(MemberInfoDto mem) {
		Map<String, Object> parm=new HashMap<String, Object>();
		parm.put("user_id",mem.getUser_id());
		parm.put("vip",mem.getVip());
		parm.put("desc",mem.getDesc());
		parm.put("expiry_time",mem.getExpiry_time());
		parm.put("update_by",mem.getUpdate_by());
		memberInfoDao.insertYjxMemberInfo(parm);
	}
	public void updYjxMemberInfo(MemberInfoDto mem) {
		Map<String, Object> parm=new HashMap<String, Object>();
		if(mem.getMember_id()==null ||mem.getMember_id().equals(" ")){
			return;
		}
		parm.put("member_id",mem.getMember_id());
		List<MemberInfoDto> tep=memberInfoDao.getOneYjxMemberInfo(parm);
		for (MemberInfoDto memberInfoDto : tep) {
			parm.put("last_expiry_time", memberInfoDto.getExpiry_time());
		}
		parm.put("user_id",mem.getUser_id());
		parm.put("vip",mem.getVip());
		parm.put("desc",mem.getDesc());
		parm.put("expiry_time",mem.getExpiry_time());
		memberInfoDao.updYjxMemberInfo(parm);
	}
	public void delYjxMemberInfo(Map<String, Object> parm) {
		memberInfoDao.delYjxMemberInfo(parm);
	}
	
	// 获取用户信息 用于添加会员
	public Page getYjxUserInfo(Map<String, Object> parm, Integer pageNum,
			Integer pageSize) {
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize = memberInfoDao.getYjxUserInfCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}
		// 分页检索
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<UserInfoDto> data = memberInfoDao.pageGetYjxUserInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}
	
	//获取一会员信息
	public List<MemberInfoDto> getOneMemberInfo(Map<String, Object> parm) {
		return memberInfoDao.getOneMemberInfo(parm);
	}
	//获取单个 一键秀会员信息
	public List<MemberInfoDto> getOneYjxMemberInfo(Map<String, Object> parm) {
		return memberInfoDao.getOneYjxMemberInfo(parm);
	}
	
	
	
	
	
	
	
	public MemberInfoDao getMemberInfoDao() {
		return memberInfoDao;
	}

	public void setMemberInfoDao(MemberInfoDao memberInfoDao) {
		this.memberInfoDao = memberInfoDao;
	}
}
